var CODE_MIRROR;

var METHOD = {
		PUT : "PUT",
		POST : "POST",
		HEAD : "HEAD",
		DELETE : "DELETE",
		OPTIONS : "OPTIONS",
		TRACE : "TRACE"
};

var REXY_URL = "/arex/it/aqquadro/RaimondRex";
var AJAX_CONTENT_TYPE = "application/json";
var AJAX_DATA_TYPE = "json";
var AJAX_CALL;

var CALL_BODY = {
	message : "roarrrrr!",
	status : "angry"
};

function onLoad() {
	var codeMirrorOpt = {
			mode:  {
				name: "javascript",
				json: true
			}
	};
	
	CODE_MIRROR = CodeMirror(document.body, codeMirrorOpt);
}

function call(callMethod, dataType) {
	if ( AJAX_CALL ) AJAX_CALL.abort();
	AJAX_CALL = $.ajax({
					  url: REXY_URL,
					  success: arexCallback,
					  contentType : AJAX_CONTENT_TYPE,
					  data: JSON.stringify(CALL_BODY),
					  dataType: dataType || AJAX_DATA_TYPE,
					  type: callMethod
				});
}

function arexCallback( jsonResponse ) {
	CODE_MIRROR.setValue(JSON.stringify(jsonResponse));
	$("#responseHeaders").html(AJAX_CALL.getAllResponseHeaders());
}